define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'shortvideo/script/index' + location.search,
                    add_url: 'shortvideo/script/add',
                    edit_url: 'shortvideo/script/edit',
                    del_url: 'shortvideo/script/del',
                    multi_url: 'shortvideo/script/multi',
                    import_url: 'shortvideo/script/import',
                    table: 'shortvideo_script',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'episode_producer_id', title: __('Episode_producer_id')},
                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'media_id', title: __('Media_id')},
                        {field: 'file', title: __('File'), operate: false, formatter: Table.api.formatter.file},
                        {field: 'file_360p', title: __('File_360p'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'file_480p', title: __('File_480p'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'file_720p', title: __('File_720p'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'file_2k', title: __('File_2k'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'file_4k', title: __('File_4k'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'score', title: __('Score'), operate:'BETWEEN'},
                        {field: 'score_num', title: __('Score_num')},
                        {field: 'like_num', title: __('Like_num')},
                        {field: 'width', title: __('Width')},
                        {field: 'height', title: __('Height')},
                        {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2'),"3":__('Type 3'),"4":__('Type 4')}, formatter: Table.api.formatter.normal},
                        {field: 'video_type', title: __('Video_type'), searchList: {"1":__('Video_type 1'),"2":__('Video_type 2')}, formatter: Table.api.formatter.normal},
                        {field: 'image_type', title: __('Image_type'), searchList: {"1":__('Image_type 1'),"2":__('Image_type 2')}, formatter: Table.api.formatter.normal},
                        {field: 'is_banner', title: __('Is_banner'), searchList: {"1":__('Is_banner 1'),"2":__('Is_banner 2')}, formatter: Table.api.formatter.normal},
                        {field: 'share_title', title: __('Share_title'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'share_image', title: __('Share_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'share_blurb', title: __('Share_blurb'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'weigh', title: __('Weigh'), operate: false},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'channel', title: __('Channel'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'total_number', title: __('Total_number')},
                        {field: 'is_allow', title: __('Is_allow'), searchList: {"1":__('Is_allow 1'),"2":__('Is_allow 2')}, formatter: Table.api.formatter.normal},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
